package com.mingsoft.led.camera;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import com.mingsoft.led.util.Configure;

public class CameraBean {

	private static CameraBean cameraBean = new CameraBean();

	public static CameraBean getInstance() {
		return cameraBean;
	}

	private Map<String, CameraConfig> cameraConfigures = new HashMap<String, CameraConfig>();

	private CameraBean() {
		update();
	}

	public void update() {
		cameraConfigures.clear();
		int i = 0;
		String str = null;
		while (null != (str = Configure.getInstance().get(
				Configure.KEY_CAMERA_CFG + i++))) {
			CameraConfig cc = CameraConfig.parse(str);
			if (cc != null) {
				cameraConfigures.put(cc.getName(), cc);
			}
		}
		for (CameraConfig c : cameraConfigures.values()) {
			System.out.println(c.toString());
		}
	}

	private String[] names = null;

	public String[] getNames() {
		if (names == null) {
			names = cameraConfigures.keySet().toArray(new String[0]);
			Arrays.sort(names);
		}
		return names;
	}

	public CameraConfig getCameraConfigByName(String key) {
		return cameraConfigures.get(key);
	}
}
